package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-31
 * Time: 9:50
 */
public class TestDemo {

    static class Counter{
         public  int count = 0;
         public synchronized void increase() {
             count++;
         }
    }
    public static void main(String[] args) {
        Counter counter = new Counter();
         Thread t1 = new Thread(()->{
             for(int i =0;i<50000;++i){
                 counter.increase();
             }
         });
         t1.start();
         Thread t2 = new Thread(()->{
             for(int i =0;i<50000;++i){
                 counter.increase();
             }
         });
         t2.start();


        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(counter.count);
    }


}
